Page({
  data: {
    allActives: [
      {
        id: 1,
        cover: '/images/actives1.png',
        title: '法律宣讲 熟知诈骗手段',
        description: '文化教育类活动，包含法律知识讲解等', 
        userIcon: '/images/avatar.png',
        userName: '布布镜子',
        scale: 1,
        opacity: 1,
        category: '文化教育',
        browseCount: 0,
        location: '社区会议室'
      },
      {
        id: 2,
        cover: '/images/actives2.png',
        title: '感知春色 小区绕城健身慢跑',
        description: '体育健康类活动，围绕小区慢跑锻炼',
        userIcon: '/images/avatar.png',
        userName: '彼酷哩',
        scale: 1,
        opacity: 1,
        category: '体育健康',
        browseCount: 0,
        location: '小区跑道'
      },
      {
        id: 3,
        cover: '/images/actives3.png',
        title: '小区八旬独身老人慰问',
        description: '志愿服务类活动，关爱老人行动',
        userIcon: '/images/avatar.png',
        userName: '哈哈哈',
        scale: 1,
        opacity: 1,
        category: '志愿服务',
        browseCount: 0,
        location: '老年活动中心'
      },
      {
        id: 4,
        cover: '/images/actives4.jpg',
        title: '团圆佳节 中秋灯谜会',
        description: '节日主题类活动，中秋灯谜庆祝',
        userIcon: '/images/avatar.png',
        userName: '酷哩',
        scale: 1,
        opacity: 1,
        category: '节日主题',
        browseCount: 0,
        location: '小区广场'
      }
    ],
    categories: [],
    currentCategory: '',
    filteredActives: []
  },

  onLoad() {
    // 提取所有唯一的分类
    const categories = [...new Set(this.data.allActives.map(item => item.category))];
    this.setData({
      categories,
      currentCategory: categories[0],
      filteredActives: this.filterActivesByCategory(categories[0])
    });
  },

  onCategoryClick(e) {
    const category = e.currentTarget.dataset.category;
    const filteredActives = this.filterActivesByCategory(category);
    this.setData({
      currentCategory: category,
      filteredActives
    });
  },

  filterActivesByCategory(category) {
    return this.data.allActives.filter(item => item.category === category);
  },

  navigateToDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/activesdetail/activesdetail?id=${id}`
    });
  }
})